import simpleGit from "simple-git";
import parseDiff from "parse-diff";


type GetChangeFilesType = {
  /** 项目路径 */
  projectPath?: string;
  /** 来源分支 */
  from?: string;
  /** 目标分支 */
  to?: string;
  /** 文件夹 */
  path?: string
};

/** 获取变更文件 */
const getChangeFiles = async (options: GetChangeFilesType) => {
  const {
    projectPath = "./",
    from = "dev",
    to = "master",
    path = "",
  } = options;
  const git = simpleGit(projectPath, {
    binary: "git",
  });
  const result = await git.diff([from, to, path]);
  return parseDiff(result).map((item) => {
    return item.from;
  });
}

export default getChangeFiles
